// clients/owmClient.js
//.数据源客户端
const axios = require('axios');

class OWMClient {
  constructor(apiKey) {
    this.client = axios.create({
      baseURL: 'https://api.openweathermap.org/data/2.5',
      timeout: 30000, // 10秒超时
      params: { appid: apiKey }
    });
  }

  async getAirQuality(lat, lon) {
    try{
    const response = await this.client.get('/air_pollution', {
      params: { lat, lon }
    });
    return response.data;
  } catch (error) {
    console.error('OpenWeatherMap 请求失败:', {
      url: error.config.url,
      code: error.code,
      message: error.message
    });
    throw error;
  }
}
}

module.exports = OWMClient;